<div class="row">
	<div class="col-lg-12">
		<h1 class="site-h1" style="background-color:#FFFFFF;">
			板块列表<#if blockmanagementList??>（${blockmanagementList.totalElements!''}）</#if>
			<span style="float:right;">
				<button class="layui-btn layui-btn-small green" href="/admin/blockmanagement/add.html" data-toggle="ajax"  data-href-index="/admin/blockmanagement/index"  data-width="80%" data-height="95%" data-title="新建板块/分类">
					新建板块/分类
				</button>
			</span>
		</h1>
		<div class="row" style="padding:5px;">
			<div class="col-lg-12">
				<table class="layui-table" lay-skin="line" id="example-basic">
				  <thead>
					<tr>
					  <th>板块名称</th>
					  <th>分类名称</th>
					  <th>添加人</th>
					  <th>发布时间</th>
					  <th style="white-space:nowrap;" nowrap="nowrap">操作</th>
					</tr> 
				  </thead>
				  <tbody>
					<#if blockmanagementList?? && blockmanagementList??>
					<#list blockmanagementList.content as blockmanagement>
					<tr data-tt-id="${blockmanagement.id!''}" data-tt-parent-id="${blockmanagement.parentid!''}" data-tt-branch="true">
					  <td class="add"><span class='folder'></span>${blockmanagement.blockname!''}</td>
					  <td></td>
					  <td>${blockmanagement.user!''}</td>
					  <td>${blockmanagement.createtime!?string("yyyy-MM-dd HH:mm:ss")}</td>
					  <td style="white-space:nowrap;" nowrap="nowrap">		
					  		<a href="/admin/blockmanagement/edit.html?id=${blockmanagement.id!''}" data-toggle="ajax" data-href-index="/admin/blockmanagement/index" data-width="80%" data-height="95%" data-title="编辑用户信息">
					  			<i class="layui-icon">&#xe642;</i>
					  			编辑
					  		</a>
					  		<a href="/admin/blockmanagement/delete.html?id=${blockmanagement.id!''}" style="margin-left:10px;" data-toggle="tip" data-title="请确认是否删除记录？">
					  			<i class="layui-icon" style="color:red;">&#x1006;</i>
					  			删除
					  		</a>
					  </td>
					</tr>
					</#list>
					</#if>
				  </tbody>
				</table>
			</div> 	   
		</div>
		<div class="row" style="padding:5px;">
			<div class="col-lg-12" id="page" style="text-align:center;"></div>
		</div>
	</div>	
</div>
<script>
	var list= [],treetable;
	<#list blockmanagementList.content as list>
		list.push({"parentid":"${list.parentid!''}","id":"${list.id!''}","name":"${list.blockname!''}","children":[]});
	</#list>
	console.log(list);
	$("#example-basic").treetable({
		expandable: true,
		clickableNodeNames:true,
		//展开  
		onNodeExpand: function() {
			var node = this;
			//是否已经加载  
			var html = loadHtml(node.id);
			$("#example-basic").treetable("unloadBranch", node);
			$("#example-basic").treetable("loadBranch", node, html);

		}
	});
	
	function loadHtml(id) {
		var str = '';
		$.ajax({
			  type:"POST",
			  url:"/admin/blockmanagement/prentId/" + id,
			  async:false,
			  dataType:"json",
			  success:function(data){
					$.each(data, function(i, item) {
						str += '<tr data-tt-id="' + item.id + '" data-tt-parent-id="' + id + '"  data-tt-branch="' + (item.leaf ? "true" : "false") + '">' +
							'<td></td>' +
							'<td>' + (item.leaf ? '<span class="folder"></span>' : '<span class="file"></span>') + item.blockname + '</td>' +
							'<td>' + item.user + '</td>' +
							'<td>' + getNowDate(item.createtime) + '</td>' +
							'<td style="white-space:nowrap;" nowrap="nowrap">' +		
						  		'<a href="/admin/blockmanagement/edit.html?id=' + item.id + '" data-toggle="ajax" data-href-index="/admin/blockmanagement/index" data-width="80%" data-height="95%" data-title="编辑用户信息">' +
						  			'<i class="layui-icon">&#xe642;</i>编辑' +
						  		'</a>' +
						  		'<a href="/admin/blockmanagement/delete.html?id=' + item.id + '" style="margin-left:10px;"  data-href-index="/admin/blockmanagement/index" data-toggle="tip" data-title="请确认是否删除记录？">' +
						  			'<i class="layui-icon" style="color:red;">&#x1006;</i>删除' +
						  		'</a>' +
						  	'</td>' +
							'</tr>';
					});
			  }
		  })
		  return str;
	}
	
	function getNowDate(date) {
		var myDate = new Date(date);
		var year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
		var month = myDate.getMonth(); //获取当前月份(0-11,0代表1月)
		var day = myDate.getDate(); //获取当前日(1-31)
		var hour = myDate.getHours();
		var minute = myDate.getMinutes();
		var seconds = myDate.getSeconds();
		var time = formate(year) + "-" + formate(month + 1) + "-" + formate(day) + " " + formate(hour) + ":" + formate(minute) + ":" + formate(seconds);
		return time;
	}

	function formate(myDate) {
		return myDate > 9 ? myDate : '0' + myDate;
	}
	
	layui.use(['laypage', 'layer'], function(){
	  var laypage = layui.laypage
	  ,layer = layui.layer;
	  laypage({
			cont: 'page'
			,pages: <#if blockmanagementList??>${blockmanagementList.totalPages}<#else>0</#if> //总页数
			,curr:<#if blockmanagementList??>${blockmanagementList.number+1}<#else>0</#if>
			,groups: 5 //连续显示分页数
			,jump:function(data , first){
				if(!first){
					location.href = "/admin/blockmanagement/list.html?p="+data.curr ;
				}
			}
	   });
	  
	  
	  
	  
	});
</script>